package com.laoda.ikun_food.controller.web.rest;

import at.favre.lib.crypto.bcrypt.BCrypt;
import com.laoda.ikun_food.entity.Order;
import com.laoda.ikun_food.entity.User;
import com.laoda.ikun_food.service.OrderService;
import com.laoda.ikun_food.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;


@RestController
@AllArgsConstructor
@RequestMapping("/api/user")
public class SaveUserRestController {
    private final UserService userService;

    @PostMapping("/reg")
    public String saveOrAdd(@RequestBody User users) {
        String pwd = users.getPassword();
        pwd = BCrypt.withDefaults().hashToString(10, pwd.toCharArray());
        users.setPassword(pwd);
        userService.save(users);
        return "ok";
    }
    private final OrderService orderService;
    @PostMapping("/Home")
    public String saveOrder(@RequestBody Order order) {
        BigDecimal price= order.getPrice();
       // String priceStr = price.toString();
       // priceStr = BCrypt.withDefaults().hashToString(10, priceStr.toCharArray());
        order.setPrice(price);

        orderService.save(order);
        return "ok";
    }


}
